package app.fugema.shop.main.login.view;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;

import com.base.common.utils.OnClickCheckedUtil;
import com.base.common.utils.UIUtils;
import com.base.common.view.base.BaseActivity;
import com.base.common.view.base.BaseFragment;
import com.base.common.viewmodel.BaseViewModel;
import app.fugema.shop.R;
import app.fugema.shop.databinding.ForgetPasswordActivityBinding;

public class ForgetPassWordActivity extends BaseActivity<ForgetPasswordActivityBinding, BaseViewModel> {

    public static void lunch(Context context, String title)
    {
        Intent intent = new Intent(context, ForgetPassWordActivity.class);
        intent.putExtra("title", title);
        context.startActivity(intent);
    }

    private enum Item {

        verification("获取验证码", SafetyVerificationFragment.newInstance()),
        password("设置新密码", SetNewPasswordFragment.newInstance()),
        pwdresult("设置结果",ChangePwdResultFragment.newInstance());

        public String name;
        public BaseFragment fragment;

        Item(String name, BaseFragment fragment) {
            fragment.setTitle(name);
            this.name = name;
            this.fragment = fragment;
        }

    }

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.forget_password_activity);
    }

    @Override
    protected void initView()
    {
        String titleStr = getIntent().getStringExtra("title");
        if(UIUtils.isNotEmpty(titleStr) && titleStr.equals("找回支付密码"))
        {
            setFindPayPwd(true);
        }
        binding.tvTitle.setText(titleStr);
        binding.ivBack.setOnClickListener(new OnClickCheckedUtil() {
            @Override
            public void onClicked(View view) {
                finish();
            }
        });
        binding.cvpViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return ForgetPassWordActivity.Item.values()[position].name;
            }

            @Override
            public int getCount() {
                return ForgetPassWordActivity.Item.values().length;
            }

            @NonNull
            @Override
            public Fragment getItem(int position)
            {
                return ForgetPassWordActivity.Item.values()[position].fragment;
            }
        });
    }

    private String cert = "";

    public void setCert(String cert)
    {
        this.cert = cert;
    }

    public String getCert()
    {
        return cert;
    }

    private boolean isFindPayPwd = false;

    public boolean isFindPayPwd()
    {
        return isFindPayPwd;
    }

    public void setFindPayPwd(boolean findPayPwd)
    {
        isFindPayPwd = findPayPwd;
    }

    public void setNewPasswordView()
    {
        //((SetNewPasswordFragment) ForgetPassWordActivity.Item.values()[1].fragment).setmPhoneNum(phone);
        binding.cvpViewPager.setCurrentItem(1, true);
    }

    public void setChangeResultView()
    {
        binding.cvpViewPager.setCurrentItem(2, true);
    }
}
